{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import numpy as np\n",
    "import os\n",
    "import pandas as pd\n",
    "import urllib2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(253208, 8)\n",
      "(253208, 8)\n",
      "(253208, 8)\n",
      "(253208, 8)\n"
     ]
    }
   ],
   "source": [
    "coins = ['BTC', 'LTC', 'ETH', 'XMR']\n",
    "df_list=[]\n",
    "for coin in coins:\n",
    "    url = 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_'+coin+'&start=1439014500&end=9999999999&period=300'\n",
    "    openUrl = urllib2.urlopen(url)\n",
    "    r = openUrl.read()\n",
    "    openUrl.close()\n",
    "    d = json.loads(r.decode())\n",
    "    print pd.DataFrame(d).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "url = 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_ETH&start=1356998100&end=9999999999&period=300'\n",
    "openUrl = urllib2.urlopen(url)\n",
    "r = openUrl.read()\n",
    "openUrl.close()\n",
    "d = json.loads(r.decode())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Close</th>\n",
       "      <th>Timestamp</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.75</td>\n",
       "      <td>1439014500</td>\n",
       "      <td>0.33</td>\n",
       "      <td>1.61</td>\n",
       "      <td>0.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.85</td>\n",
       "      <td>1439014800</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.85</td>\n",
       "      <td>1439015100</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.85</td>\n",
       "      <td>1439015400</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.85</td>\n",
       "      <td>1439015700</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "      <td>1.85</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Close   Timestamp  High   Low  Open\n",
       "0   1.75  1439014500  0.33  1.61  0.33\n",
       "1   1.85  1439014800  1.85  1.85  1.85\n",
       "2   1.85  1439015100  1.85  1.85  1.85\n",
       "3   1.85  1439015400  1.85  1.85  1.85\n",
       "4   1.85  1439015700  1.85  1.85  1.85"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(d)\n",
    "original_columns=[u'close', u'date', u'high', u'low', u'open']\n",
    "new_columns = ['Close','Timestamp','High','Low','Open']\n",
    "df = df.loc[:,original_columns]\n",
    "df.columns = new_columns\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import h5py\n",
    "with h5py.File(''.join(['data/bitcoin2015to2017_wf.h5']), 'r') as hf:\n",
    "    datas = hf['inputs'].value\n",
    "    labels = hf['outputs'].value\n",
    "    input_times = hf['input_times'].value\n",
    "    output_times = hf['output_times'].value\n",
    "    original_inputs = hf['original_inputs'].value\n",
    "    original_outputs = hf['original_outputs'].value\n",
    "    original_datas = hf['original_datas'].value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "original_inputs[0].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df.to_csv('data/bitcoin2015to2017.csv',index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
